package com.reefe.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.reefe.entity.Result;
import com.reefe.entity.ZTreeNode;
import com.reefe.pojo.TbItemCat;
import com.reefe.service.ItemCatService;
import com.reefe.utils.ResultUtil;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *商品类目
 */
@RestController
@RequestMapping("/item/cat")
public class ItemCatControler {

    @Reference(version = "1.0.0")
    private ItemCatService itemCatServiceImpl;

    @RequestMapping(value="/list",method ={RequestMethod.GET})
    public List<ZTreeNode> getItemCatAll(@RequestParam(value="id", defaultValue="0")Long parentId) {
        List<ZTreeNode> catList = itemCatServiceImpl.getCatList(parentId);
        return catList;
    }


    @RequestMapping(value="/update",method ={RequestMethod.POST})
    public Result updateItemCat(@ModelAttribute TbItemCat tbItemCat) {
        itemCatServiceImpl.updateItemCat(tbItemCat);
        return new ResultUtil<Object>().setData(null);
    }

    @RequestMapping(value="/add",method ={RequestMethod.POST})
    public Result addItemCat(@ModelAttribute TbItemCat tbItemCat) {
        itemCatServiceImpl.addItemCat(tbItemCat);
        return new ResultUtil<TbItemCat>().setData(null);
    }

    @RequestMapping(value="/del/{id}",method ={RequestMethod.DELETE})
    public Result delItemCat(@PathVariable("id") long id) {
        itemCatServiceImpl.deleteItemCat(id);
        return new ResultUtil<TbItemCat>().setData(null);
    }


}
